package com.h2cloud.redisTest;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.BinaryClient;
import redis.clients.jedis.Jedis;

import java.util.List;

/**
 * @Package: com.h2cloud.redisTest
 * @ClassName: TestList
 * @Author: h2cloud
 * @CreateTime: 2021/4/17 8:41 下午
 * @Description:
 */
public class TestList {
    private Jedis jedis;

    @Before
    public void before() {
        this.jedis = new Jedis("127.0.0.1", 6379);
    }

    @After
    public void after() {
        jedis.close();
    }

    //测试List相关
    @Test
    public void testList() {

        //lpush
        jedis.lpush("names1", "张三5", "王五5", "赵柳5", "win7");

        //rpush
        jedis.rpush("names1", "xiaomingming");

        jedis.expire("names1", 5);

        //lrange

        List<String> names1 = jedis.lrange("names1", 0, -1);
        names1.forEach(name -> System.out.println("name = " + name));

        //lpop rpop
        String names11 = jedis.lpop("names1");
        System.out.println(names11);

        //llen
        jedis.linsert("names1", BinaryClient.LIST_POSITION.BEFORE, "xiaohei", "xiaobai");

    }

}

